/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Client.GUI.SwingWorkers;

import Client.GUI.OperationInProgress;
import Library.Common.GUIOperations;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JTextPane;
import javax.swing.JTree;
import javax.swing.SwingWorker;

/**
 *
 * @author larabenito
 */
public class CreateTreeWorker extends SwingWorker<Boolean, Void> {

    private OperationInProgress progressWindow;
    private ObjectInputStream input;
    private ObjectOutputStream output;
    private Boolean isServerInvoked;
    //Texto a imprimir en las pantallas de estado:
    private String statusText;
    private JTextPane panelToUpdate;
    //Especifico de este Worker:
    private JTree treeToUpdate;
    
    public CreateTreeWorker(ObjectInputStream input, ObjectOutputStream output, 
            Boolean isServerInvoked, String statusText, JTextPane panelToUpdate, 
            JTree treeToUpdate){
        progressWindow = new OperationInProgress();
        this.input = input;
        this.output = output;
        this.isServerInvoked = isServerInvoked;
        this.statusText = statusText;
        this.panelToUpdate = panelToUpdate;
        this.treeToUpdate = treeToUpdate;
    }
    
    @Override
    protected Boolean doInBackground() throws Exception {
        progressWindow.setVisible(true);
        //Aquí van las operaciones pesadas:
        GUIOperations.updateTextPane(panelToUpdate, "Actualizando Árbol de Directorios (" + statusText + ")");
        treeToUpdate.setModel(GUIOperations.getTreeFinal(statusText, isServerInvoked, input, output));
        GUIOperations.updateTextPane(panelToUpdate, "Árbol de Directorios Actualizado");
        //Fin de las operaciones pesadas
        progressWindow.setVisible(false);
        return true;
    }
    
}
